﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Whe;
using WOS;
using WOS.Common;

namespace WOS.Upload
{

   

    public sealed class UploadEntry : Entry
    {
        #region Private Fields
        private readonly UploadStatus status;
        private readonly DataSize size;

        private readonly UploadFile[] files;
        private readonly UploadPoint[] points;
        private readonly UploadLink[] links;
        #endregion
        #region Constructors
        public UploadEntry(Guid id, string name, int index, UploadStatus status, DataSize size, UploadFile[] files, UploadPoint[] points, UploadLink[] links, Func<Progress> progressFactory, Func<Speed> speedFactory, Func<Estimate> estimateFactory)
            : base(id, name, index, progressFactory, speedFactory, estimateFactory)
        {
            this.status = status;
            this.size = size;
            this.files = files;
            this.points = points;
            this.links = links;
        }
        #endregion

        #region Public Members
        public UploadStatus Status
        {
            get { return this.status; }
        }

        public DataSize Size
        {
            get { return this.size; }
        }

        public UploadFile[] GetFiles()
        {
            return this.files;
        }

        public UploadPoint[] GetPoints()
        {
            return this.points;
        }

        public UploadLink[] GetLinks()
        {
            return this.links;
        }

        public override bool CanBeStarted()
        {
            return this.status == UploadStatus.Stopped && this.links.Any();
        }

        public override bool CanBeStopped()
        {
            return this.status == UploadStatus.Queued || this.status == UploadStatus.Working;
        }

        public override bool IsFinished()
        {
            return this.status == UploadStatus.Finished;
        }
        #endregion
    }

    public class UploadEntryEventArgs : EventArgs
    {
        #region Private Fields
        private readonly UploadEntry target;
        #endregion
        #region Constructors
        public UploadEntryEventArgs(UploadEntry target)
        {
            this.target = target;
        }
        #endregion

        #region Public Members
        public UploadEntry Target
        {
            get { return this.target; }
        }
        #endregion
    }

    public sealed class UploadFile
    {
        #region Private Fields
        private readonly Guid id;
        private readonly string name;
        private readonly string path;
        private readonly DataSize size;
        #endregion
        #region Constructors
        public UploadFile(Guid id, string name, string path, DataSize size)
        {
            this.id = id;
            this.name = name;
            this.path = path;
            this.size = size;
        }
        #endregion

        #region Public Members
        public Guid Id
        {
            get { return this.id; }
        }

        public string Name
        {
            get { return this.name; }
        }

        public string Path
        {
            get { return this.path; }
        }

        public DataSize Size
        {
            get { return this.size; }
        }
        #endregion
    }

   
    public sealed class UploadLink
    {
        #region Private Fields
        private readonly Guid id;
        private readonly Uri value;
        private readonly UploadFile file;
        private readonly UploadPoint point;
        private readonly UploadLinkStatus status;
        #endregion
        #region Constructors
        public UploadLink(Guid id, Uri value, UploadFile file, UploadPoint point, UploadLinkStatus status)
        {
            this.id = id;
            this.value = value;
            this.file = file;
            this.point = point;
            this.status = status;
        }
        #endregion

        #region Public Members
        public Guid Id
        {
            get { return this.id; }
        }

        public Uri Value
        {
            get { return this.value; }
        }

        public UploadFile File
        {
            get { return this.file; }
        }

        public UploadPoint Point
        {
            get { return this.point; }
        }

        public UploadLinkStatus Status
        {
            get { return this.status; }
        }
        #endregion
    }

    public sealed class UploadPoint
    {
        #region Private Fields
        private readonly Guid id;
        private readonly ProviderInfo provider;
        private readonly AccountInfo account;
        #endregion
        #region Constructors
        public UploadPoint(Guid id, ProviderInfo provider, AccountInfo account)
        {
            this.id = id;
            this.provider = provider;
            this.account = account;
        }
        #endregion

        #region Public Members
        public Guid Id
        {
            get { return this.id; }
        }

        public ProviderInfo Provider
        {
            get { return this.provider; }
        }

        public AccountInfo Account
        {
            get { return this.account; }
        }
        #endregion
    }
}
